#include<bits/stdc++.h>
using namespace std;
#define M 200007
int c=1;
long long t,n,m,l,hi;
long long detect[M];
long long ans1=0;
int de[M][3];
bool vis[M];
struct str{
    int d;
    int v;
    int a;
};
str car[M];
bool jud(int d,int v,int a)
{
    if(a==0)
    {
        if(v<=hi) return 0;
        for(int j=1;j<=m;j++)
        {
            if(detect[j]>=d)
            {
                de[c][0]=j;
                de[c][1]=m;
                c++;
                return 1;
            }
        }
        return 0;
    }
    else if(a>0)
    {
        float lb=(hi*hi-v*v)/a/2.0+d;
        if(lb>=l) return 0;
        for(int j=1;j<=m;j++)
        {
            if(detect[j]>lb)
            {
                de[c][0]=j;
                de[c][1]=m;
                c++;
                return 1;
            }
        }
        return 0;
    }
    else
    {
        float ub=(hi*hi-v*v)/a/2.0+d;
        if(v<=hi) return 0;
        for(int j=1;j<=m;j++)
        {
            if(detect[j]>=ub) break;
            if(detect[j]>=d)
            {
                de[c][0]=j;
                for(int k=j+1;k<=m;k++)
                {
                    if(detect[k]>=ub)
                    {
                        de[c][1]=k-1;
                        c++;
                        return 1;
                    }
                }
                de[c][1]=m;
                c++;
                return 1;
            }
        }
        return 0;
    }
    return 0;
}
int dfs(int n,int x)
{
    int ans=0,minn=INT_MAX;
    if(n>=c+1)
    {
        return x;
    }
    for(int i=de[n][0];i<=de[n][1];i++)
    {
        if(vis[i]) return dfs(n+1,x);
        vis[i]=1;
        ans=dfs(n+1,x+1);
        vis[i]=0;
        if(ans<minn) minn=ans;
    }
    return minn;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int ti=0;ti<t;ti++)
    {
        ans1=0;
        c=1;
        memset(vis,0,sizeof(vis));
        memset(de,0,sizeof(de));
        memset(car,0,sizeof(car));
        memset(detect,0,sizeof(detect));
        cin>>n>>m>>l>>hi;
        for(int i=1;i<=n;i++)
        {
            cin>>car[i].d>>car[i].v>>car[i].a;
        }
        for(int i=1;i<=m;i++)
        {
            cin>>detect[i];
        }
        sort(detect+1,detect+m+1);
        for(int i=1;i<=n;i++)
        {
            if(jud(car[i].d,car[i].v,car[i].a)) ans1++;
        }
        cout<<ans1<<" "<<m-dfs(1,0)+1<<endl;
    }
    return 0;
}
